/********************************** (C) COPYRIGHT *******************************
 * File Name          : gattprofile.h
 * Author             : WCH
 * Version            : V1.0
 * Date               : 2018/12/11
 * Description        :
 *********************************************************************************
 * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
 * Attention: This software (modified or not) and binary are used for 
 * microcontroller manufactured by Nanjing Qinheng Microelectronics.
 *******************************************************************************/

#ifndef GATTPROFILE_H
#define GATTPROFILE_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************************************************************
 * INCLUDES
 */

/*********************************************************************
 * CONSTANTS
 */

// Profile Parameters
#define IPV4_FLAG                    1
#define IPPORT_FLAG                  2
#define DEV_ID_FLAG                  3
#define SNSR_FRQ_FLAG               10
#define DATA_UP_FRQ_FLAG            11
#define CFG_UP_FRQ_FLAG             12
#define GPS_UP_FRQ_FLAG             13
#define CNCT_FRQ_FLAG               14
#define WARN_CH4_FLAG               20
#define EARLY_CH4_FLAG              21
#define LOW_TEMP_FLAG               22
#define HIGH_TEMP_FLAG              23
#define LOW_BAT_FLAG                24
#define DATA_SHOW_FLAG              30
#define GPS_SHOW_FLAG               31
//need password
#define DEV_TYPE_FLAG               40
#define CNCT_CMD_FLAG               41
#define CFG_BIN_FLAG                42
#define DATA_BIN_FLAG               43
#define GPS_BIN_FLAG                44
#define PSWD_ROOT_FLAG              50
#define PSWD_USER_IN_FLAG           51
#define PSWD_USER_MD_FLAG           52
#define DEV_ID_MDFY_FLAG            53
#define SIMPLEPROFILE_CHAR4         88

// Simple Profile Service UUID
#define SIMPLEPROFILE_SERV_UUID     0xFF00

// Key Pressed UUID
#define IPV4_UUID                   0xFF01
#define IPPORT_UUID                 0xFF02
#define DEV_ID_UUID                 0xFF03
#define SNSR_FRQ_UUID               0xFF04
#define DATA_UP_FRQ_UUID            0xFF05
#define CFG_UP_FRQ_UUID             0xFF06
#define GPS_UP_FRQ_UUID             0xFF07
#define CNCT_FRQ_UUID               0xFF08
#define WARN_CH4_UUID               0xFF09
#define EARLY_CH4_UUID              0xFF0A
#define LOW_TEMP_UUID               0xFF0B
#define HIGH_TEMP_UUID              0xFF0C
#define LOW_BAT_UUID                0xFF0D
#define DATA_SHOW_UUID              0xFF10
#define GPS_SHOW_UUID               0xFF11
//need password
#define DEV_TYPE_UUID               0xFF20
#define CNCT_CMD_UUID               0xFF21
#define CFG_BIN_UUID                0xFF22
#define DATA_BIN_UUID               0xFF23
#define GPS_BIN_UUID                0xFF24
#define PSWD_ROOT_UUID              0xFF30
#define PSWD_USER_IN_UUID           0xFF31
#define PSWD_USER_MD_UUID           0xFF32
#define DEV_ID_MDFY_UUID            0xFF33
#define SIMPLEPROFILE_CHAR4_UUID    0xFFE4

// Simple Keys Profile Services bit fields
#define SIMPLEPROFILE_SERVICE       0x00000001

// Length of characteristic in bytes ( Default MTU is 23 )
#define IPV4_VALUE_LEN              (15+1)
#define IPPORT_VALUE_LEN             (5+1)     //65535
#define DEV_ID_VALUE_LEN            (10+1)     //4,294,967,295
#define SNSR_FRQ_VALUE_LEN           (4+1)     //5~1440min
#define DATA_UP_FRQ_VALUE_LEN        (4+1)     //5~1440min
#define CFG_UP_FRQ_VALUE_LEN         (3+1)     //1~255hr
#define GPS_UP_FRQ_VALUE_LEN         (3+1)     //1~255day
#define CNCT_FRQ_VALUE_LEN           (3+1)     //1~255hr
#define WARN_CH4_VALUE_LEN           (3+1)     //0~5% -- 0~500
#define EARLY_CH4_VALUE_LEN          (3+1)     //0~5% -- 0~500
#define LOW_TEMP_VALUE_LEN           (4+1)     //-40~80 -- -400~800
#define HIGH_TEMP_VALUE_LEN          (4+1)     //-40~80 -- -400~800
#define LOW_BAT_VALUE_LEN            (2+1)     //2.0~3.6 -- 20~36
#define DATA_SHOW_VALUE_LEN          (128)
#define GPS_SHOW_VALUE_LEN            (64)
//need password
#define DEV_TYPE_VALUE_LEN             (4)
#define CNCT_CMD_VALUE_LEN            (64)
#define CFG_BIN_VALUE_LEN             (64)
#define DATA_BIN_VALUE_LEN            (64)
#define GPS_BIN_VALUE_LEN             (64)
#define PSWD_ROOT_VALUE_LEN           (11)
#define PSWD_USER_IN_VALUE_LEN        (11)
#define PSWD_USER_MD_VALUE_LEN        (11)
#define DEV_ID_MDFY_VALUE_LEN         (11)
#define SIMPLEPROFILE_CHAR4_LEN         1

/*********************************************************************
 * TYPEDEFS
 */

/*********************************************************************
 * MACROS
 */

/*********************************************************************
 * Profile Callbacks
 */

// Callback when a characteristic value has changed
typedef void (*simpleProfileChange_t)(uint8_t paramID, uint8_t *pValue, uint16_t len);

typedef struct
{
    simpleProfileChange_t pfnSimpleProfileChange; // Called when characteristic value changes
} simpleProfileCBs_t;

/*********************************************************************
 * API FUNCTIONS
 */

/*
 * SimpleProfile_AddService- Initializes the Simple GATT Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 */

extern bStatus_t SimpleProfile_AddService(uint32_t services);

/*
 * SimpleProfile_RegisterAppCBs - Registers the application callback function.
 *                    Only call this function once.
 *
 *    appCallbacks - pointer to application callbacks.
 */
extern bStatus_t SimpleProfile_RegisterAppCBs(simpleProfileCBs_t *appCallbacks);

/*
 * SimpleProfile_SetParameter - Set a Simple GATT Profile parameter.
 *
 *    param - Profile parameter ID
 *    len - length of data to right
 *    value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16_t will be cast to
 *          uint16_t pointer).
 */
extern bStatus_t SimpleProfile_SetParameter(uint8_t param, uint16_t len, void *value);

/*
 * SimpleProfile_GetParameter - Get a Simple GATT Profile parameter.
 *
 *    param - Profile parameter ID
 *    value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16_t will be cast to
 *          uint16_t pointer).
 */
extern bStatus_t SimpleProfile_GetParameter(uint8_t param, void *value);

/*
 * simpleProfile_Notify - Send notification.
 *
 *    connHandle - connect handle
 *    pNoti - pointer to structure to notify.
 */
extern bStatus_t simpleProfile_Notify(uint16_t connHandle, attHandleValueNoti_t *pNoti);

/*********************************************************************
*********************************************************************/

#ifdef __cplusplus
}
#endif

#endif
